package gamebackend;

import generators.BasicBlockGenerator;
import generators.BlockRule;
import generators.EndCapGenerator;
import generators.HorizontalStreakGenerator;
import generators.SoloHorizontalKiller;
import generators.VerticalStreakGenerator;
import gui.BlockStyle;

import framework.Color;
import java.util.Random;

public class CrateBiome extends GameSession.Biome{
	private double my_lengthBeforeChange;
	private boolean my_gap = true;
	private Block my_gray;
	private Block my_green;

	public CrateBiome(GameSession the_session,
			int the_tier, Random the_random, double the_length) {
		the_session.super(the_session, the_tier, the_random, the_length);
		addEasyPath(new FlightPath(Block.PRIMARY_PATH, getEasyPath(), 40,
				new EasyFlier(getRandom(), 15, getGameSession().getWidth() - 15)), getLength());
		addHardPath(new FlightPath(Block.SECONDARY_PATH, getHardPath(), 16,
				new EasyFlier(getRandom(), 8, getGameSession().getWidth() - 8)), getLength());
		
		my_gray = new Block(BlockStyle.METAL, new Color(95, 95, 90));
		my_green = new Block(BlockStyle.METAL, new Color(90, 125, 70));
		final Block blue = new Block(BlockStyle.METAL, new Color(70, 100, 250));
		
		addGenerator(new HorizontalStreakGenerator(getRandom(), .6, HorizontalStreakGenerator.LEFT), getLength());
		addGenerator(new HorizontalStreakGenerator(getRandom(), .6, HorizontalStreakGenerator.BOTH), getLength());
		
		addGenerator(new EndCapGenerator(my_gray), getLength());
		
		addGenerator(new VerticalStreakGenerator(my_green, getRandom(), .07), getLength());
		addGenerator(new VerticalStreakGenerator(blue, getRandom(), .07), getLength());
		addGenerator(new VerticalStreakGenerator(new Block(BlockStyle.METAL, new Color(70, 100, 251)), getRandom(), .07), getLength());
		addGenerator(new VerticalStreakGenerator(new Block(BlockStyle.METAL, new Color(90, 126, 70)), getRandom(), .07), getLength());
		addGenerator(new SoloHorizontalKiller(my_gray), getLength());
	}
	public void step(final double the_yChange) {
		super.step(the_yChange);
		if (my_lengthBeforeChange < 0) {
			my_gap = !my_gap;
			if (my_gap) {
				my_lengthBeforeChange += 200 - 25 * getTier();
				getEasyPath().setFlier(new MoveToFlier(getEasyPath().getXPosition()));
				getHardPath().setFlier(new MoveToFlier(getHardPath().getXPosition()));
				addGenerator(new BasicBlockGenerator(my_gray, BlockRule.EMPTY, getRandom(), 1), my_lengthBeforeChange);
				addGenerator(new BasicBlockGenerator(my_green, BlockRule.ANY, getRandom(), .075 * getTier()), my_lengthBeforeChange);
			} else {
				my_lengthBeforeChange += 1200 + 300 * getTier();
				getEasyPath().setFlier(new EasyFlier(getRandom(), 15, getGameSession().getWidth() - 15));
				getHardPath().setFlier(new EasyFlier(getRandom(), 8, getGameSession().getWidth() - 8));
				
			}
		}
		my_lengthBeforeChange -= the_yChange;
	}

}
